{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d56f3cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# list（列表）是一种有序的集合，可以随时添加和删除其中的元素\n",
    "# 特点：1.支持增删改查\n",
    "#       2.列表中的数据可改变（内存地址不变）\n",
    "#       3.用中括号[]来表示列表类型，数据项之间用逗号隔开，数据项可以是任何类型的数据\n",
    "#       4.支持索引和切片操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f9f01651",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 1, 2, 3]\n"
     ]
    }
   ],
   "source": [
    "#列表可以进行乘法运算，例如：\n",
    "list=[1,2,3]\n",
    "print(list*2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "08df77ff",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "#还可以对列表进行索引，例如：\n",
    "list=[1,2,3]\n",
    "print(list[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b40c35a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "# len()可以检测列表的长度，例如：\n",
    "list = [1,2,3]\n",
    "print(len(list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5bf027fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "# append()可以在列表末端添加一个新的数据项，例如：\n",
    "list = [1,2,3]\n",
    "list.append(4)#使用方法 -》 列表名.append（需要添加的数据项）\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "95a7ccd4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3]\n"
     ]
    }
   ],
   "source": [
    "# insert（）可以在列表中指定的位置添加新的数据项，例如：\n",
    "list = [1,2,3]\n",
    "list.insert(0,0)#使用方法 -》 列表名.insert（插入的位置，需要添加的数据项）\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "670b3070",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "# extend（）可以将另一个序列添加进来，例如：\n",
    "list1 = [1,2,3]\n",
    "list2 = [4,5,6]\n",
    "list1.extend(list2)\n",
    "print(list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9da525d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3]\n"
     ]
    }
   ],
   "source": [
    "# del 可以永久删除列表中的数据项，也可以删除指定的数据项，例如：\n",
    "list = [1,2,3]\n",
    "del list[0]\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a4b37a8a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3]\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "#pop() 可以取出列表中的某一数据项，但不是删除它，例如：\n",
    "list = [1,2,3]\n",
    "a = list.pop(0)#取出而不是删除\n",
    "print(list)\n",
    "print(a)#打印取出的数据项"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "dc21a0d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "#index（）可以获取指定数据项的索引值，例如：\n",
    "list = [1,2,3]\n",
    "print(list.index(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83598db7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
